package yingke.com.yingke.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.Toast;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.SaveCallback;

import yingke.com.yingke.R;

public class SignatureActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText signature_et;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_signature);
        initView();
    }

    private void initView() {
        findViewById(R.id.signature_back_iv).setOnClickListener(this);
        findViewById(R.id.signature_change_tx).setOnClickListener(this);
        signature_et = (EditText) findViewById(R.id.signature_et);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.signature_change_tx:
                final String new_signature = signature_et.getText().toString().trim();
                AVUser.getCurrentUser().saveInBackground(new SaveCallback() {
                    @Override
                    public void done(AVException e) {
                        AVUser.getCurrentUser().put("signature", new_signature);
                        AVUser.getCurrentUser().saveInBackground();
                    }
                });
                finish();
                Toast.makeText(this, "更改成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.signature_back_iv:
                finish();
                break;
        }
    }
}
